package com.example.imtao.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;

import com.example.imtao.LoginActivity;
import com.example.imtao.R;
import com.example.imtao.adapter.MainHeaderAdAdapter;
import com.example.imtao.adapter.MainMenuAdapter;
import com.example.imtao.util.DataUtil;

import java.util.Objects;

public class MainFragment extends Fragment {

    protected int [] icons = {R.mipmap.header_pic_ad1, R.mipmap.header_pic_ad2, R.mipmap.header_pic_ad1};
    protected ViewPager mVPagerHeaderAd;

    protected int [] menuIcons = {R.mipmap.menu_airport, R.mipmap.menu_car, R.mipmap.menu_course,
            R.mipmap.menu_hatol, R.mipmap.menu_nearby, R.mipmap.menu_ticket,
            R.mipmap.menu_train, R.mipmap.menu_trav, };
    protected String [] menus;
    protected RecyclerView mRecycleViewMenu;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        menus = this.requireActivity().getResources().getStringArray(R.array.main_menu);

        mVPagerHeaderAd = (ViewPager) rootView.findViewById(R.id.vpager_main_header_ad);
        mRecycleViewMenu = (RecyclerView) rootView.findViewById(R.id.recycleview_main_menu);

        MainHeaderAdAdapter adAdapter = new MainHeaderAdAdapter(getActivity(), DataUtil.getHeaderAddInfo(getActivity(), icons));
        mVPagerHeaderAd.setAdapter(adAdapter);

        // 菜单
        // 布局样式
        mRecycleViewMenu.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        MainMenuAdapter mainMenuAdapter = new MainMenuAdapter(getActivity(), DataUtil.getMainMenus(menuIcons, menus));
        mRecycleViewMenu.setAdapter(mainMenuAdapter);

        return rootView;

    }





}
